﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class THouse : BaseRepository<THouseInfo>, ITHouse
    {
        private const string PARM_HOUSE_PRODUCTSN = "@ProductSN";
        private const string PARM_HOUSE_MOID = "@MOID";

        public IList<THouseInfo> LoadEntities()
        {
            return null;
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public THouseInfo LoadEntity<T1>(T1 productSN)
        {   
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntity("THouse_selectbySN", parm);
        }

        public IList<THouseInfo> GetTHousesbyMO(string moID)
        {
            SqlParameter parm = new SqlParameter(PARM_HOUSE_MOID, SqlDbType.NVarChar, 50); 
            parm.Value = moID;
            return ExcuteSqlToGetEntities("THouse_selectbyMO", parm);
        }



        // 通过条码 获取对应的批号MO（标签打印软件对接）
        public THouseInfo ProductMOID_GetbySN(string ProductSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = ProductSN;
            return ExcuteSqlToGetEntity("WEB_ProductMOID_GetbySN", parm);
        }


        //-------------------------------------重写超类基础操作---------------------------------------------------------




        public override THouseInfo GetEntityRecord(SqlDataReader rdr)
        {
            THouseInfo pro = new THouseInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString());
            return pro;
        }

        public override THouseInfo GetEntityRecord()
        {
            THouseInfo pro = new THouseInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "THouse_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return "THouse_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_HOUSE_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_HOUSE_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_HOUSE_MOID, SqlDbType.NVarChar, 50),
                };
            return parms;
        }

        public override void SetParameters(THouseInfo house, params SqlParameter[] Parms)
        {
            Parms[0].Value = house.ProductSN;
            Parms[1].Value = house.MOID;
        } 
    }
}
